package com.haierp.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.haierp.model.Item;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.WxUserVO;
import com.wangzhixuan.commons.shiro.ShiroUser;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haierp.mapper.WxUserMapper;
import com.haierp.model.WxUser;
import com.haierp.service.IWxUserService;

@Service("wxUserService")
public class WxUserServiceImpl extends SuperServiceImpl<WxUserMapper, WxUser>  implements IWxUserService {

	@Override
	public WxUser queryWxUser(String openId) {
		EntityWrapper<WxUser> wrapper = new EntityWrapper<WxUser>();
		wrapper.where("open_id={0}", openId);
		List<WxUser>  user= this.baseMapper.selectList(wrapper);
		if(user!=null&&!user.isEmpty()){
			return user.get(0);
		}
		return null;
	}

	@Override
	public JsonPageResult<List<WxUser>> queryFans(WxUserVO wxUserVO) {
		JsonPageResult<List<WxUser>> result = new JsonPageResult<>();
		Integer totalCount =  this.baseMapper.queryFansCount(wxUserVO);

		//2、查询分页记录
		if(totalCount!=null&&totalCount!=0){
			result.buildPage(totalCount, wxUserVO);
			List<WxUser> wxUsers = this.baseMapper.queryFans(wxUserVO);
			result.setData(wxUsers);
		}else{
			List<WxUser> wxUsers  = new ArrayList<>();
			result.setData(wxUsers);
		}
		return result;
	}
}
